﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Profile.cs" company="DissingNellemann">
//   
// All rights reserved </copyright>
// <summary>
//   The profile.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Website.Models.Domain
{
    using System.Linq;

    using Website.Models.Base;
    using Website.Models.ViewModels;

    /// <summary>
    ///     The profile.
    /// </summary>
    public class Profile : Entity
    {
        #region Public Properties

        /// <summary>
        ///     Gets or sets the cvr.
        /// </summary>
        public string CVR { get; set; }

        /// <summary>
        ///     Gets or sets the contact type.
        /// </summary>
        public ProfileContactType ContactType { get; set; }

        /// <summary>
        ///     Gets or sets the location.
        /// </summary>
        public Location Location { get; set; }

        /// <summary>
        ///     Gets or sets the name.
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        ///     Gets or sets the relation.
        /// </summary>
        public ProfileRelation Relation { get; set; }

        /// <summary>
        ///     Gets or sets the sub type.
        /// </summary>
        public ProfileSubtype SubType { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="dto">
        /// The dto.
        /// </param>
        /// <param name="view">
        /// The view.
        /// </param>
        /// <returns>
        /// The <see cref="Profile"/>.
        /// </returns>
        public static Profile Convert(CRUDServices.Profile dto, ProfilesView view)
        {
            return new Profile
                       {
                           ID = dto.ID, 
                           Name = dto.Name, 
                           CVR = dto.CVR, 
                           Relation = view.Relations.SingleOrDefault(x => x.ID.Equals(dto.Relation)), 
                           SubType = view.Subtypes.SingleOrDefault(x => x.ID.Equals(dto.SubType)), 
                           Location = view.Locations.SingleOrDefault(x => x.ID.Equals(dto.Location))
                       };
        }

        #endregion
    }
}